#include <iostream>
#include <unordered_map>
#include <string>

bool is_prime(int n) {
    if (n <= 1) {
        return false;
    }
    if (n <= 3) {
        return true;
    }
    if (n % 2 == 0 || n % 3 == 0) {
        return false;
    }
    int i = 5;
    while (i * i <= n) {
        if (n % i == 0 || n % (i + 2) == 0) {
            return false;
        }
        i += 6;
    }
    return true;
}

int next_prime(int num) {
    while (true) {
        if (is_prime(num)) {
            return num;
        }
        num += 1;
    }
}

int prev_prime(int num) {
    while (true) {
        if (is_prime(num)) {
            return num;
        }
        num -= 1;
    }
}

int main() {
    std::unordered_map<std::string, int> num_dict = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    std::string input;
    std::getline(std::cin, input);
    std::string num_words[3];
    int num_index = 0;
    std::string current_word = "";
    for (char c : input) {
        if (c == ' ') {
            num_words[num_index++] = current_word;
            current_word = "";
        } else {
            current_word += c;
        }
    }
    num_words[num_index] = current_word;

    try {
        int num = std::stoi(std::to_string(num_dict[num_words[0]]) + std::to_string(num_dict[num_words[1]]) + std::to_string(num_dict[num_words[2]]));
        if (is_prime(num)) {
            std::cout << num << std::endl;
        } else {
            int smaller_prime = prev_prime(num - 1);
            int larger_prime = next_prime(num + 1);
            if (std::abs(num - smaller_prime) <= std::abs(num - larger_prime)) {
                std::cout << smaller_prime << std::endl;
            } else {
                std::cout << larger_prime << std::endl;
            }
        }
    } catch (...) {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}

